package andycpp;

public class calculate {
		number num1=new number();
		number num2=new number();
		calculate(number a,number b){
			this.num1=a;
			this.num2=b;
		}
		int MaxGys(int a,int b){
			int i=1,t=1;
			for(i=1;i<=a&&i<=b;i++){
				if(a%i==0&&b%i==0){
					t=i;
				}
			}
			return t;
		}
		number simplification(number a){
			int x=MaxGys(Math.abs(a.denominator),Math.abs(a.numerator));
			a.denominator=a.denominator/x;
			a.numerator=a.numerator/x;
			return a;
		}
		number add(){
			int numD,num1N,num2N;
			numD=num1.denominator*num2.denominator;
			num1N=num1.denominator*num2.numerator;
			num2N=num2.denominator*num1.numerator;
			int MaxGys=MaxGys(numD,num1N+num2N);
			number result=new number();
			result.denominator=numD/MaxGys;
			result.numerator=(num1N+num2N)/MaxGys;
			result=simplification(result);
			return result;
		}
		number sub(){
			int numD,num1N,num2N;
			numD=num1.denominator*num2.denominator;
			num1N=num1.denominator*num2.numerator;
			num2N=num2.denominator*num1.numerator;
			int MaxGys=MaxGys(numD,num1N+num2N);
			number result=new number();
			result.denominator=numD/MaxGys;
			result.numerator=(num1N-num2N)/MaxGys;
			result=simplification(result);
			return result;
		}
		number muti(){
			int numD,numN;
			numD=num1.denominator*num2.denominator;
			numN=num1.numerator*num2.numerator;
			number result=new number();
			result.denominator=numD;
			result.numerator=numN;
			result=simplification(result);
			return result;
		}	
		number div(){
			int numD,numN;
			numD=num1.denominator*num2.numerator;
			numN=num1.numerator*num2.denominator;
			number result=new number();
			result.denominator=numD;
			result.numerator=numN;
			result=simplification(result);
			return result;
		}	
	}